// 主界面
;
define(function(require, exports, module) {
	'use strict';
	var util = require("util");
	var base = require("base");
	var leftMenu = require("../leftMenu/leftMenu");
	var topMenu = require("../topMenu/topMenu");
	var router = require("../hash/pageRouter");
	var footer = require("../footer/footer_main");
	var dialog = require("dialog");
	var validate = require("validate");
	var databind = require("databind");
	var pageIndex = 1,
		pageSize = 10,
		totalPageCount = 1,
		totalRecordCount = 0; // 分页初始化
	var imgSrc;
	var noticeState = 1;
	var init = function(top, left) {
		
		var left = 0;
		if (base.getUrlParam("left")) {
			left = new Number(base.getUrlParam("left")) - 1;
		}
		if (base.getUrlParam("noticeState")) {
			noticeState = base.getUrlParam("noticeState");
		}
		leftMenu.init(1);
		topMenu.init(1);
		$(".table-section").removeClass("none");
		footer.init();
		$("#footer").removeClass("none");
		$("#leftMenu2").find(".leftMenu-item").removeClass("leftMenu-active");
		$("#leftMenu2 .leftMenu li:first-child").addClass("leftMenu-open");
		$("#leftMenu2").find(".leftMenu-item").eq(left).addClass("leftMenu-active");
		inquireTransportNoticePageList();
		initEvent();
		router.init();
	};
	var initEvent = function() {
		// 若未登录，则返回登陆页面
		if (base.getData("sid") == null || base.getData("sid") == "" || base.getData("sid") == undefined) {
			top.location.href = "../login/login.html";
		}

		/* 新增的点击事件 */
		$("#leftMenu2").on("click", "#transportDoingList", function() {
			location.href = "../transportNotice/transportNoticeList.html?noticeState=2&left=2";
		});
		$("#leftMenu2").on("click", "#transportFinishedList", function() {
			location.href = "../transportNotice/transportNoticeList.html?noticeState=3&left=3";
		});
		// 搜索按钮
		$("#transport_notice_search").on("click", function() {
			pageIndex = 1;
			pageSize = 10;
			totalPageCount = 1;
			totalRecordCount = 0; //分页初始化
			inquireTransportNoticePageList();
		});
	};

	// 查询收货通知列表
	var inquireTransportNoticePageList = function() {
		var body = base.parseForm($(".page-content-search"));
		var params = {
			pageIndex: pageIndex,
			pageSize: pageSize,
			noticeState: noticeState
		}
		base.apply(params, body);

		base.fnAjax({
			action: "inquireTransportNoticePageList.json",
			oData: params, // 传递参数
			fnSuccess: function(data) {
				if (data.status == 200) {
					var tpl = $("#transportNoticeListTpl").html();
					var html = juicer(tpl, data);
					$("#transportNoticeListBody").html(html);
					totalPageCount = data.totalPageCount;
					totalRecordCount = data.totalRecordCount;
					base.pageControl($("#pagenation"), totalRecordCount, data.pageIndex, data.pageSize, function(p) {
						pageIndex = p;
						inquireTransportNoticePageList();
					});
					//详情
					$(".handle-type").unbind("click").click(function() {
						var transportNoticeId = $(this).parent().parent().attr("transportNoticeId");
						var $this = $(this).parents("tr.tr_style");
						router.route("transportNotice/transportNoticeDetail.html?transportNoticeId=" + transportNoticeId);
					});
				} else {
					base.alert(2, "信息获取失败");
				}
			}
		});
	}
	return {
		init: init
	};
});